﻿#include"ToothBoundary.h"
#include"ToothCoordinateInfo.h"
#include"FaccInfo.h"
#include"StateBeforeClose.h"
#include"SaveStatus.h"
#include"Total.h"

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<stack>
/// <summary>
///思路：111111
/// 1.一个符号栈stack_来控制符号匹配，用于查看数据块是否输入结束
/// 2.把对数字字符串做的操作和对名称字符串做的操作抽象成函数
/// </summary>
/// <returns></returns>


/// <summary>
/// 1.point接下来处理大量x，y，z数据，需要cur_cnt判断将值传送给x,y,z哪一个
/// 2.先记录当前符号栈的元素个数cnt，当碰到左括号压栈，右括号弹栈，逗号中止对一个数的读取
/// 3.当符号栈cnt与之前记录的栈中元数个数相同时，表示point输入完毕
/// </summary>
/// <param name="File">引用方式传入正在读的文件</param>
/// <param name="middle_value">引用方式传入当前字符</param>
/// <param name="point_cnt">当前符号栈大小</param>
/// <param name="stack_">符号栈</param>
/// <returns></returns>
Point ProcessPoint(std::ifstream& File, char& middle_value, int& point_cnt, std::stack<char>& stack_) {

	using namespace std;
	Point B_point;
	int cur_cnt = 0;
	string buff_;

	while (stack_.size() == point_cnt) {
		File.get(middle_value);
		if (middle_value == '[') {
			stack_.push(middle_value);
			cur_cnt = 0;
		}
		else if (middle_value == ']') {
			cur_cnt = 0;
			if (stack_.top() == '[') stack_.pop();//将左括号弹栈,弹栈时stack_.size()<point_cnt
		}
		else if ((middle_value >= '0' && middle_value <= '9') || middle_value == '.') {
			buff_.clear();
			while (middle_value != ',' && middle_value != ']' && middle_value != '\n') {
				buff_.push_back(middle_value);
				File.get(middle_value);
			}
			double data = stod(buff_);
			if (cur_cnt == 0) B_point.set_point_x(data);
			else if (cur_cnt == 1) B_point.set_point_y(data);
			else if (cur_cnt == 2) {
				B_point.set_point_z(data);//最后一个数据
				return B_point;
			}
			if (middle_value == ',') { cur_cnt++; }
		}
	}
	return B_point;
}
void  ProcessStack(char middle_value, std::stack<char>& stack_) {
	if (middle_value == '[' || middle_value == '{') {
		stack_.push(middle_value);//压栈
	}
	else if (middle_value == ']') {
		if (stack_.top() == '[') { 
			stack_.pop();
		}
	}
	else if (middle_value == '}') {
		if (stack_.top() == '{') { 
			stack_.pop();
		}
	}
}
void  ProcessPoint(std::ifstream& File, Point& cur_point, char& middle_value) {
	//因为此时的point有名字，所以选择的是引用传参一个先有名字的point，不返回值，不用读左括号.
	using namespace std;
	string buff_;
	int cur_cnt = 0;//用来控制哪个数字放进 x , y , z
	while (middle_value != ']') {
		if ((middle_value >= '0' && middle_value <= '9') || middle_value == '.') {
			buff_.clear();
			while ((middle_value >= '0' && middle_value <= '9') || middle_value == '.') {
				buff_.push_back(middle_value);
				File.get(middle_value);
			}
			double date = stod(buff_);
			if (cur_cnt == 0) {
				cur_point.set_point_x(date);
			}
			else if (cur_cnt == 1) {
				cur_point.set_point_y(date);
			}
			else if (cur_cnt == 2) {
				cur_point.set_point_z(date);
			}
			if (middle_value == ',') cur_cnt++;
		}
		File.get(middle_value);
	}
}
void  ProcessUpperLower(std::ifstream& File, ToothBoundaryInfo& toothBoundary_, std::string buff_, char& middle_value, std::stack<char>& stack_) {
	using namespace std;
	Point B_point;
	ToothPosition toothPosition_1;
	toothPosition_1.set_name(buff_);
	toothBoundary_.tooth_boundary_Info.push_back(toothPosition_1);//1为upper||lower信息，将其挂在前边传进来的的toothboundary上
	//upper之后读到第一个中括号，代表所有upper数据开始，此时获得符号栈大小，控制upper整体数据的获取
	while (middle_value != '[') {
		File.get(middle_value);
	}
	stack_.push(middle_value);
	int stack_cnt = stack_.size();
	File.get(middle_value);

	//以下处理tooth_position ：包括多个（toothId+points）
	while (stack_.size() >= stack_cnt) {
		SubToothPosition sub_tooth_position_;
		while (!((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) && (stack_.size() >= stack_cnt)) {//过滤toothid英文字符之前的其他字符
			ProcessStack(middle_value, stack_);
			File.get(middle_value);
		}//先过除了名字和数字外的其他字符
		//接下来获取tooid字符数据
		if (!(stack_.size() >= stack_cnt)) { 
			break;
		}
		while (!(middle_value <= '9' && middle_value >= '0')) {//过到数字区域
			File.get(middle_value);
		}
		//以下获取toothid数字
		buff_.clear();
		while (middle_value != ',' && middle_value != ']') {
			buff_.push_back(middle_value);
			File.get(middle_value);
		}
		int data = stoi(buff_);
		sub_tooth_position_.set_toothId(data);
		while (!((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z'))) {
			File.get(middle_value);
		}
		//接下来获取points的字符数据
		buff_.clear();
		while ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
			buff_.push_back(middle_value);
			File.get(middle_value);
		}

		int point_stack_cnt = stack_.size();
		while (stack_.size() >= point_stack_cnt) {//以下是处理poins数据,stack_.size()>point_satck_cnt+1,就进入处理point的循环
			ProcessStack(middle_value, stack_);
			if (stack_.size() > point_stack_cnt + 1) {//传入当前的stack_size()，调用point函数，处理每个point数据；
				int point_cnt = stack_.size();
				B_point = ProcessPoint(File, middle_value, point_cnt, stack_);
				sub_tooth_position_.A_points_.push_back(B_point);
			}
			File.get(middle_value);
		}
		toothPosition_1 = toothBoundary_.tooth_boundary_Info.back();
		toothBoundary_.tooth_boundary_Info.pop_back();//记得弹出
		toothPosition_1.tooth_position.push_back(sub_tooth_position_);//新增的在这块把sub数据压入
		toothBoundary_.tooth_boundary_Info.push_back(toothPosition_1);
	}
}
void  ProcessAttachmenInfoUpper(std::ifstream& File, AttachmentInfo attachment_info_1, std::string  buff_, char& middle_value, std::stack<char>& stack_) {
	ToothPosition tooth_position_1;
	tooth_position_1.set_name(buff_);
	buff_.clear();
	attachment_info_1.attachment_info.push_back(tooth_position_1);
	while (middle_value != '，') { 
		File.get(middle_value);
	}//过到逗号，代表upper数据结束
}
void  ProcessAttachmentInfoLower(std::ifstream& File, AttachmentInfo attachment_info_1, std::string  buff_, char& middle_value, std::stack<char>& stack_) {
	ToothPosition tooth_position_1;//stack_cnt=3
	tooth_position_1.set_name(buff_);
	int stack_cnt = stack_.size();
	while (middle_value != ']') {
		File.get(middle_value);
	}
	File.get(middle_value);
}
void  ProcessJawStatus(std::ifstream& File, SubSaveStatus& sub_save_status_1, int cur_stack_size, char& middle_value, std::stack<char>& stack_) {
	JawStatus cur_jaw_status;
	std::string buff_, buff_2;//分别用来放数字和名称
	while (stack_.size() >= cur_stack_size) {//cur_stack_size=4,此时传进来的middle_value=[
		File.get(middle_value);
		ProcessStack(middle_value, stack_);
		if (middle_value == '"') {//先获取冒号前的字符串，再获取逗号前的数字
			buff_.clear();
			while (middle_value != ':') {
				if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
					buff_.push_back(middle_value);
				}
				File.get(middle_value);
			}
			if (buff_ == "jawType") {
				buff_2.clear();
				while (middle_value != ',') {
					if (middle_value >= '0' && middle_value <= '9') {
						buff_2.push_back(middle_value);
					}
					File.get(middle_value);
				}
				int date = stoi(buff_2);
				cur_jaw_status.jawType = date;
			}
			else if (buff_ == "jawMatrix") {
				int cnt = 0;
				buff_2.clear();
				while (middle_value != ']') {
					buff_2.clear();
					while (middle_value != ',' && middle_value != ']') {
						if (middle_value == '.' || (middle_value >= '0' && middle_value <= '9')) {
							buff_2.push_back(middle_value);
						}
						File.get(middle_value);
					}
					float date = stof(buff_2);
					cur_jaw_status.jawMatrix.set_matrix(cnt, date);
					if (middle_value == ',') {
						cnt++;
						File.get(middle_value);
					}
				}
				sub_save_status_1.sub_save_status_jaw.push_back(cur_jaw_status);
			}
		}
	}
}
void  ProcessTeethStatus(std::ifstream& File, SubSaveStatus& sub_save_status_1, int cur_stack_size, char& middle_value, std::stack<char>& stack_) {
	TeethStatus cur_teeth_status;//这个类有三个元素：toothId，isExtraction，matrix
	std::string buff_, buff_2;
	while (stack_.size() >= cur_stack_size) {//cur_stack_size=4，代表teethstatus元素开始
		File.get(middle_value);
		ProcessStack(middle_value, stack_);
		//先获取冒号前的字符串，再获取逗号前的数字
		if (middle_value == '"') {
			buff_.clear();
			while (middle_value != ':') {
				if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
					buff_.push_back(middle_value);
				}
				File.get(middle_value);
			}
			if (buff_ == "toothId") {
				buff_2.clear();
				while (middle_value != ',') {
					if (middle_value >= '0' && middle_value <= '9') {
						buff_2.push_back(middle_value);
					}
					File.get(middle_value);
				}
				int date = stoi(buff_2);
				cur_teeth_status.set_toothId(date);
			}
			else if (buff_ == "isExtraction") {
				buff_2.clear();
				while (middle_value != ',') {
					if (middle_value >= '0' && middle_value <= '9') {
						buff_2.push_back(middle_value);
					}
					File.get(middle_value);
				}
				int date = stoi(buff_2);
				cur_teeth_status.set_isExtraction(date);
			}
			else if (buff_ == "matrix") {
				int cnt = 0;
				buff_2.clear();
				while (middle_value != ']') {
					buff_2.clear();
					while (middle_value != ',' && middle_value != ']') {
						if (middle_value == '.' || (middle_value >= '0' && middle_value <= '9')) {
							buff_2.push_back(middle_value);
						}
						File.get(middle_value);
					}
					float date = stof(buff_2);
					cur_teeth_status.matrix.set_matrix(cnt, date);
					if (middle_value == ',') {
						cnt++;
						File.get(middle_value);
					}
				}
				File.get(middle_value);
				sub_save_status_1.sub_save_staatus_teeth.push_back(cur_teeth_status);
			}
		}
	}
}
void  ProcessAttachmentInfo(std::ifstream& File, std::stack<char>& stack_, AttachmentInfo& attachment_info_1, char& middle_value) {
	while (middle_value != '{') { 
		File.get(middle_value); 
	}
	stack_.push(middle_value);
	File.get(middle_value);
	int stack_cnt = stack_.size();//3
	std::string buff_;
	while (stack_.size() >= stack_cnt) {
		if (middle_value == '"') {
			buff_.clear();
			while (middle_value != ':') {
				if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
					buff_.push_back(middle_value);
				}
				File.get(middle_value);
			}
			if (buff_ == "upper") {
				while (middle_value != ',') { 
					File.get(middle_value);
				}
			}
			else if (buff_ == "lower") {
				while (middle_value != ']') { 
					File.get(middle_value);
				}
				File.get(middle_value);
				break;
			}
		}
		File.get(middle_value);
	}
	while (stack_.size() > stack_cnt - 1) {
		File.get(middle_value);
		if (middle_value == '}') {
			if (stack_.top() == '{')stack_.pop();
		}
	}//将符号栈弹到只剩两个
}
std::string ProcessBuff(std::ifstream& File,char& middle_value) {
	std::string buff_;
	buff_.clear();
	while ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
		buff_.push_back(middle_value);
		File.get(middle_value);
	}
	return buff_;
}
SubToothCoordinateInfo ProcessSubToothCoordinateInfo(std::ifstream& File, int stack_cnt, std::string buff_, char& middle_value, std::stack<char>& stack_) {
	//处理每个sub信息，每个sub包括一个id和多个point,stack_cnt=2,永远等于2;//返回每个sub信息，直接连接在上面外部声明的父类中
	using namespace std;
	SubToothCoordinateInfo Sub_Tooth_Coordinate_Info_1;
	//先往后读，知道碰到tooid字符，然后获取进入while循环，边界条件是stack_.size()==2时退出

	while (!((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z'))) {
		ProcessStack(middle_value, stack_);
		File.get(middle_value);
	}//以上的stack_.size()等于3,获取toothid

	while (!(middle_value >= '0' && middle_value <= '9')) {
		File.get(middle_value);
	}
	 buff_.clear();
	while (middle_value >= '0' && middle_value <= '9') {
		buff_.push_back(middle_value);//将数字压入字符串中
		File.get(middle_value);
	}
	int data = stoi(buff_);
	Sub_Tooth_Coordinate_Info_1.set_toothId(data);

	//接下来是while循环，获取多个point数据
	//第一轮进入，stack.size()=3,stack_cnt=2;刚进入这个循环，middle_value=，
	while (stack_.size() > stack_cnt) {//也就是大于2时不停的读数据,新加了等于号，试验一下效果
		//分三类：括号，字符、数字
		if (middle_value == '[' || middle_value == '{') {
			stack_.push(middle_value);
		}
		else if (middle_value == ']') {
			if (stack_.top() == '[') { 
				stack_.pop();
			}
		}
		else if (middle_value == '}') {
			if (stack_.top() == '{') {
				stack_.pop();
			}
		}
		else if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z') && stack_.size() > stack_cnt) {//如果获取到的是某个字符
			 buff_.clear();
			while ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z') && stack_.size() > stack_cnt) {
				buff_.push_back(middle_value);
				File.get(middle_value);
			}//获取这一串字符
			if (buff_.compare("crownCenter") == 0 || buff_.compare("coorDirectionX") == 0
				|| buff_.compare("coorDirectionY") == 0 || buff_.compare("coorDirectionZ") == 0) {//如果是这几个字符串
				Point cur_point;
				cur_point.set_name(buff_);
				ProcessPoint(File, cur_point,middle_value);//返回值为void，为什么为void ?
				Sub_Tooth_Coordinate_Info_1.points.push_back(cur_point);
			}
		}
		File.get(middle_value);
	}
	return Sub_Tooth_Coordinate_Info_1;
}
SubFaccInfo ProcessSubFaccInfo(std::ifstream& File, int stack_cnt, std::string buff_, char& middle_value, std::stack<char>& stack_) {
	using namespace std;
	SubFaccInfo sub_facc_info_1;
	//先获取tooid信息，记住此时传进来的stack_cnt=2;

	while (!((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z'))) {
		//除了英文字符之外的其他字符，过滤
		ProcessStack(middle_value, stack_);
		File.get(middle_value);
	}//以上的stack_.size()等于3，此时middle_value==",接下来获取toothid

	while (!(middle_value >= '0' && middle_value <= '9')) {
		File.get(middle_value);
	}
	 buff_.clear();
	while (middle_value >= '0' && middle_value <= '9') {
		buff_.push_back(middle_value);
		File.get(middle_value);
	}
	int data = stoi(buff_);
	sub_facc_info_1.set_toothId(data);
	//接下来是while循环，获取多个point数据
	//第一轮进入，stack.size()=3,stack_cnt=2;刚进入这个循环，middle_value=，
	while (stack_.size() > stack_cnt) {//也就是大于2时不停的读数据
		//分三类：括号，字符、数字
		if (middle_value == '[' || middle_value == '{') {
			stack_.push(middle_value);
		}
		else if (middle_value == ']') {
			if (stack_.top() == '[') {
				stack_.pop();
			}
		}
		else if (middle_value == '}') {
			if (stack_.top() == '{') {
				stack_.pop(); 
			}
		}
		else if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z') && stack_.size() > stack_cnt) {
			//如果获取到的是某个字符,
			 buff_.clear();
			while ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z') && stack_.size() > stack_cnt) {
				buff_.push_back(middle_value);
				File.get(middle_value);
			}
			if (buff_.compare("incisalEdgeCenter") == 0 || buff_.compare("midLabialPoint") == 0
				|| buff_.compare("midLingualPoint") == 0 || buff_.compare("fAPoint") == 0
				|| buff_.compare("faccDirection") == 0 || buff_.compare("edgeDirection") == 0) {//如果是这几个字符串
				Point cur_point;
				cur_point.set_name(buff_);
				ProcessPoint(File, cur_point, middle_value);
				sub_facc_info_1.points.push_back(cur_point);
				buff_.clear();
			}
		}
		File.get(middle_value);
	}
	return sub_facc_info_1;
}
SubSaveStatus ProcessSubSaveStatus(std::ifstream& File, int stack_cnt, char& middle_value, std::stack<char>& stack_) {
	//此时传入的stack_cnt=2;每个sub用中括号括起来
	using namespace std;
	SubSaveStatus sub_save_status_1;//savestatus包含多个sub,每个sub里包含多个Jaw_Status和多个Teeth_Status
	JawStatus jaw_status_1;
	TeethStatus teeth_status_1;

	std::string buff_;
	buff_.clear();
	while (middle_value != ':') {//接下来先获取名字name
		if (middle_value == '{') {
			stack_.push(middle_value);
		}
		File.get(middle_value);
	}
	while (middle_value != ',') {
		if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z') || (middle_value >= '0' && middle_value <= '9')) {
			buff_.push_back(middle_value);
		}
		File.get(middle_value);
	}
	sub_save_status_1.set_name(buff_);
	//接下来是一个jawstatus 和一个teethstatus,此时的stack_.size()=3;
	//读到第一个中括号，代表所有的jawstatus的数据开始读入
	int cur_stack_size = stack_.size();
	while (stack_.size() >= cur_stack_size) {
		//这一块读入jawstatus和一个teethstatus，获取冒号前的一段字符
		ProcessStack(middle_value, stack_);
		buff_.clear();
		while (middle_value != ':' && stack_.size() >= cur_stack_size) {
			if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
				buff_.push_back(middle_value);
			}
			File.get(middle_value);
		}
		if (buff_ == "jawStatus") {//都往后读到一个中括号
			while (middle_value != '[') { 
				File.get(middle_value);
			}
			stack_.push(middle_value);
			int stack_size = stack_.size();//4
			while (stack_.size() >= stack_size) {//第一次传进去的middle是【
				ProcessJawStatus(File, sub_save_status_1, stack_size, middle_value, stack_);
			}
		}
		else if (buff_ == "teethStatus") {
			while (middle_value != '[') { 
				File.get(middle_value);
			}
			stack_.push(middle_value);
			int stack_size = stack_.size();//4
			while (stack_.size() >= stack_size) {//第一次传进去的middle是【
				ProcessTeethStatus(File, sub_save_status_1, stack_size, middle_value, stack_);
			}
			while (middle_value != '}')File.get(middle_value);
		}
	}
	File.get(middle_value);
	return sub_save_status_1;
}
TeethMoveInfo ProcessTeethMoveInfo(std::ifstream& File, std::string name, char& middle_value, std::stack<char>& stack_) {
	TeethMoveInfo cur_teeth_move_info;
	SubTeethMoveInfo cur_sub_teeth_move_info;
	std::string buff_;
	while (middle_value != '[') {
		File.get(middle_value);
	}
	stack_.push(middle_value);//此时为3
	File.get(middle_value);
	int stack_cnt = stack_.size();
	while (stack_.size() >= stack_cnt) {
		buff_.clear();
		if (middle_value == ']') {
			if (stack_.top() == '[') { 
				stack_.pop(); 
			}
		}
		while (middle_value != '}' && stack_.size() >= stack_cnt) {//代表某个sub还没结束
			if (middle_value == ']') {
				if (stack_.top() == '[') {
					stack_.pop();
				}
			}
			if ((middle_value == '"')) {
				buff_.clear();
				while (middle_value != ':') {
					if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
						buff_.push_back(middle_value);
					}
					File.get(middle_value);
				}
				if (buff_ == "toothId") {
					buff_.clear();
					while (middle_value != ',') {
						if (middle_value >= '0' && middle_value <= '9')buff_.push_back(middle_value);
						File.get(middle_value);
					}
					int data = stoi(buff_);
					cur_sub_teeth_move_info.toothId = data;//此时结束，middle_value=','
				}
				else if (buff_ == "isExtraction") {
					buff_.clear();
					while (middle_value != ',') {
						if (middle_value >= '0' && middle_value <= '9')buff_.push_back(middle_value);
						File.get(middle_value);
					}
					int data = stoi(buff_);
					cur_sub_teeth_move_info.isExtraction = data;//此时结束，middle_value=','
				}
				else if (buff_ == "matrix") {
					int cnt = 0;
					buff_.clear();
					while (middle_value != ']') {
						buff_.clear();
						while (middle_value != ',' && middle_value != ']') {
							if (middle_value == '.' || (middle_value >= '0' && middle_value <= '9')) {
								buff_.push_back(middle_value);
							}
							File.get(middle_value);
						}
						float date = stof(buff_);
						cur_sub_teeth_move_info.matrix.set_matrix(cnt, date);
						if (middle_value == ',') {
							cnt++;
							File.get(middle_value);
						}
					}
					cur_teeth_move_info.sub_teeth_move_info.push_back(cur_sub_teeth_move_info);
				}
			}
			File.get(middle_value);
		}//以上括号处理一个数据
		File.get(middle_value);
	}
	cur_teeth_move_info;
	return cur_teeth_move_info;
}
void ReadWrite(Total& Total_) {//读写文件的函数
	using namespace std;
	using namespace BE;
	stack<char> stack_;
	Point A_point;
	std::ifstream inputFile("C:/Users/18417/Desktop/table/104235560141131/caseInfo.cmo");
	std::ofstream outputFile("C:\\Users\\18417\\Desktop\\table\\newcreatefile\\output.txt", std::ios::binary);
	if (outputFile.is_open()) {
		std::cout << "successfully create file!" << std::endl;
	}
	else {
		std::cout << "failed to open /create file" << std::endl;
	}
	if (!inputFile) {
		std::cout << "open failure for reading." << std::endl << std::endl << std::endl;
		return;
	}
	char middle_value;
	std::string buff_;
	std::vector<int>  B_int;
	int cnt = 0;
	vector<char> A_char;
	outputFile << "{" << std::endl;
	while (inputFile.get(middle_value)) {
		ProcessStack(middle_value, stack_);//处理括号
		buff_.clear();


		if (middle_value == '"') {//以下是碰到名称或者数字
			inputFile.get(middle_value);
			while (middle_value != '"') {
				buff_.push_back(middle_value);
				inputFile.get(middle_value);
			}
			if (buff_ == "toothBoundary") {
				ToothBoundaryInfo toothBoundary_1;
				toothBoundary_1.set_name(buff_);

				std::cout << "creat toothboundary successfully! " << std::endl;
				while (!((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z'))) {
					ProcessStack(middle_value, stack_);
					inputFile.get(middle_value);
				}
				//upper
				buff_.clear();
				buff_ = ProcessBuff(inputFile, middle_value);
				ProcessUpperLower(inputFile, toothBoundary_1, buff_, middle_value, stack_);
				//lower
				buff_.clear();
				while (!((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z'))) {
					inputFile.get(middle_value);
				}
				buff_.clear();
				buff_= ProcessBuff(inputFile, middle_value);
				ProcessUpperLower(inputFile, toothBoundary_1, buff_, middle_value, stack_);


				Total_.T_tooth_boundary_info = toothBoundary_1;
				
				Total_.T_tooth_boundary_info.tooth_boundary_Info.at(0).tooth_position.at(0).modify_idvalue();//修改id
				Total_.T_tooth_boundary_info.tooth_boundary_Info.at(0).tooth_position.at(0).modify_point_value();
				Total_.T_tooth_boundary_info.print_result(outputFile);
			}
			else if (buff_ == "toothCoordinateInfo") {
				std::cout << "enter toothCoordinateInfo creater!" << std::endl;
				ToothCoordinateInfo cur_tooth_coordinate_info;
				SubToothCoordinateInfo cur_sub_tooth_coordinate_info;

				cur_tooth_coordinate_info.set_name(buff_);

				
				while (middle_value != '[') {
					inputFile.get(middle_value);
				}
				stack_.push(middle_value);
				int stack_cnt = stack_.size();//stack_cnt=2
				inputFile.get(middle_value);
				char c = '\0';
				while (stack_.size() >= stack_cnt) {
					//当里边还有数据时，stack.size（）是大于等于的状态，等于状态是有其他数据没读入完成
					if (c != '\n') {
						cur_sub_tooth_coordinate_info = ProcessSubToothCoordinateInfo(inputFile, stack_cnt, buff_, middle_value, stack_);
						c = middle_value;
						cur_tooth_coordinate_info.tooth_cooridnate_info.push_back(cur_sub_tooth_coordinate_info);
					}
					else break;
				}
				Total_.T_tooth_coordinate_info = cur_tooth_coordinate_info;
				buff_.clear();
				Total_.T_tooth_coordinate_info.print_result_to_file(outputFile);
			}
			else if (buff_ == "faccInfo") {
				std::cout << "enter create faccInfo!" << std::endl;
				FaccInfo cur_facc_info;
				SubFaccInfo cur_sub_facc_info;

				cur_facc_info.set_name(buff_);
				

				while (middle_value != '[') {
					inputFile.get(middle_value);
				}
				stack_.push(middle_value);
				int stack_cnt = stack_.size();//stack_cnt=2,
				inputFile.get(middle_value);
				char c = '\0';
				while (stack_.size() >= stack_cnt) {
					//当里边还有数据时，stack.size（）是大于等于的状态，等于状态是有其他数据没读入完成
					if (c != '\n') {
						cur_sub_facc_info = ProcessSubFaccInfo(inputFile, stack_cnt, buff_, middle_value, stack_);
						c = middle_value;
						cur_facc_info.facc_info.push_back(cur_sub_facc_info);
					}
					else break;
				}
				Total_.T_facc_info = cur_facc_info;
				Total_.T_facc_info.print_result_to_file(outputFile);
			}
			else if (buff_ == "saveStatus") {
				std::cout << "enter create saveStatus! " << std::endl;
				SaveStatus cur_save_status;
				SubSaveStatus cur_sub_save_status;
				cur_save_status.set_name(buff_);
				
				//while循环进入四次获得4个sub
				while (middle_value != '[') {
					inputFile.get(middle_value);
				}
				stack_.push(middle_value);
				int stack_cnt = stack_.size();//stack_cnt=2,

				inputFile.get(middle_value);
				char c = '\0';
				while (stack_.size() >= stack_cnt) {//栈中的数据>=2,证明其中有数据
					if (c != '\n') {
						cur_sub_save_status = ProcessSubSaveStatus(inputFile, stack_cnt, middle_value, stack_);
						c = middle_value;
						cur_save_status.save_status.push_back(cur_sub_save_status);
					}
					else break;
				}
				buff_.clear();
				Total_.T_save_status = cur_save_status;
				Total_.T_save_status.print_result_to_file(outputFile);
			}
			else if (buff_ == "stateBeforeClose") {
				StatusBeforeClose status_before_close_1;
				TeethMoveInfo teeth_move_info_1;

				status_before_close_1.set_name(buff_);
				buff_.clear();
				std::cout << "enter stateBeforeClose creater!" << std::endl;
				while (middle_value != '{') { 
					inputFile.get(middle_value); 
				}
				stack_.push(middle_value);//stack_.size()=2
				int out_stack_size = stack_.size();
				inputFile.get(middle_value);

				while (stack_.size() >= out_stack_size) {
					if (middle_value == '"') {
						buff_.clear();
						while (middle_value != ':') {
							if ((middle_value >= 'A' && middle_value <= 'Z') || (middle_value >= 'a' && middle_value <= 'z')) {
								buff_.push_back(middle_value);
							}
							inputFile.get(middle_value);
						}
					}
					if (buff_ == "teethMoveInfo") {
						status_before_close_1.teeth_move_info_ = ProcessTeethMoveInfo(inputFile, buff_, middle_value, stack_);

					}
					else if (buff_ == "attachmentInfo") {
						AttachmentInfo attachment_info_1;
						cout << "enter attachmentInfo!" << endl;
						ProcessAttachmentInfo(inputFile, stack_, attachment_info_1, middle_value);
						break;
					}
					inputFile.get(middle_value);
				}
				Total_.T_status_before_close = status_before_close_1;
				Total_.T_status_before_close.print_result_to_file(outputFile);
			}
		}
	}
	outputFile << "}";
}
int main() {
	using namespace std;
	Total Total_;
	ReadWrite(Total_);
	return 0;
}